import { createRouter, createWebHistory } from 'vue-router' // 替换 Vue2 导入方式
import Layout from '@/views/layout.vue'
import Login from '@/views/login.vue'
import Home from '@/views/home.vue'

// 公共路由
export const constantRoutes = [
    // 独立登录页(移动到布局容器外部)
    {
        path: '/login',
        name: 'Login',
        component: Login,
        meta: { title: '登录' }
    },
    // 布局容器路由
    {
        path: '/',
        component: Layout,
        children: [
            {
                path: '/',
                // redirect: '/home'
            },
            // 原登录路由已移除
            {
                path: '/home',
                name: 'Home',
                component: Home,
                meta: { title: '首页' }
            }
        ]
    }
]

const router = createRouter({
    history: createWebHistory(),
    routes: constantRoutes,
    scrollBehavior(to, from, savedPosition) {
        if (savedPosition) {
            return savedPosition
        }
        return { top: 0 }
    },
})
export default router;
